package com.tsd.jxc.dashboard.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.tsd.core.utils.DateUtil;
import com.tsd.jxc.buy.dao.JxcBuyOrderMapper;
import com.tsd.jxc.buy.dao.JxcBuyReturnBillMapper;
import com.tsd.jxc.dashboard.service.JxcDashboardService;
import com.tsd.jxc.goods.dao.JxcGoodsMapper;
import com.tsd.jxc.sale.dao.JxcSaleOrderMapper;
import com.tsd.jxc.sale.dao.JxcSaleReturnBillMapper;
import com.tsd.jxc.stock.dao.JxcStockGoodsMapper;
import com.tsd.jxc.stock.dao.JxcStockInbillMapper;
import com.tsd.jxc.stock.dao.JxcStockOutbillMapper;
import com.tsd.jxc.stock.dao.JxcStockWarehouseMapper;
import com.tsd.service.BaseServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @ClassName: JxcDashboardServiceImpl
 * @Description: TODO
 * @Author: Hillpool
 * @Date: 2022/10/26 17:43
 * @Version: 1.0
 */
@Service
public class JxcDashboardServiceImpl extends BaseServiceImpl implements JxcDashboardService {

    @Resource
    private JxcStockWarehouseMapper jxcStockWarehouseMapper;
    @Resource
    private JxcGoodsMapper jxcGoodsMapper;
    @Resource
    private JxcBuyOrderMapper jxcBuyOrderMapper;
    @Resource
    private JxcSaleOrderMapper jxcSaleOrderMapper;
    @Resource
    private JxcStockInbillMapper jxcStockInbillMapper;
    @Resource
    private JxcStockOutbillMapper jxcStockOutbillMapper;
    @Resource
    private JxcStockGoodsMapper jxcStockGoodsMapper;
    @Resource
    private JxcBuyReturnBillMapper jxcBuyReturnBillMapper;
    @Resource
    private JxcSaleReturnBillMapper jxcSaleReturnBillMapper;

    @Override
    public JSONObject queryJxcDashboard() {
        Date now = new Date();
        int yyyy = DateUtil.getYyyy(now);
        int mm = DateUtil.getMm(now);
        int warehouseNum = jxcStockWarehouseMapper.countValid();
        int goodsNum = jxcGoodsMapper.countValid();
        // int goodsNum = jxcGoodsProductMapper.countValid();
        int buyNum = jxcBuyOrderMapper.countValid(yyyy, mm, null, null);
        int saleNum = jxcSaleOrderMapper.countValid(yyyy, mm, null);
        int inNum = jxcStockInbillMapper.countValid(yyyy, mm);
        int outNum = jxcStockOutbillMapper.countValid(yyyy, mm);
        int month_buy_return_bill_num = jxcBuyReturnBillMapper.countValid(yyyy, mm);
        int month_sale_return_bill_num = jxcSaleReturnBillMapper.countValid(yyyy, mm);
//        Double stock_amount = jxcStockGoodsMapper.sumAmount();

        JSONObject object = new JSONObject();
//        object.put("stock_amount", stock_amount);
        object.put("warehouse_num", warehouseNum);
        object.put("goods_num", goodsNum);
        object.put("month_buy_order_num", buyNum);
        object.put("month_sale_order_num", saleNum);
        object.put("month_stock_in_bill_num", inNum);
        object.put("month_stock_out_bill_num", outNum);
        object.put("month_buy_return_bill_num", month_buy_return_bill_num);
        object.put("month_sale_return_bill_num", month_sale_return_bill_num);
        return object;
    }

}
